package com.yuzhihao.writejvm.code.a;

import com.yuzhihao.writejvm.clazz.ClassInfo;
import com.yuzhihao.writejvm.code.Operation;
import com.yuzhihao.writejvm.code.StackFrame;
import com.yuzhihao.writejvm.format.FormsEnum;
import com.yuzhihao.writejvm.format.PrintFormat;
import com.yuzhihao.writejvm.read.Parse;
import com.yuzhihao.writejvm.read.Parses;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.extern.log4j.Log4j2;

import java.io.DataInputStream;
import java.io.IOException;

/**
 * astore
 * @author yzh
 * @see <a href="https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-6.html#jvms-6.5.astore">jvmdoc</a>
 * @since 2021年12月16日15:32:03
 */
@Data
@EqualsAndHashCode(callSuper = true)
@Log4j2
public class Astore extends Operation implements Parses {

    private FormsEnum fe = FormsEnum.astore;

    private ClassInfo ci;

    private int index_u1 = 1;

    private int cindex;

    @Override
    public StackFrame exec(StackFrame frame) {

        return frame;
    }



    @Override
    public String print(String print) {
        return print + PrintFormat.EMPTY + super.index+PrintFormat.COLON+PrintFormat.EMPTY+fe.name()+System.lineSeparator();
    }

    @Override
    public int parse(DataInputStream dis, ClassInfo ci) {
        this.setCi(ci);
        try {
            this.cindex = Parse.byteToInt(this.index_u1, dis);
        } catch (IOException e) {
            log.error(e);
        }

        return this.index_u1;
    }

}
